package artid.com.arttogoa.adapter;

import java.util.List;
import org.apache.commons.lang3.StringUtils;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import artid.com.arttogoa.R;
import artid.com.arttogoa.parser.NoiceListParser;

public class NoticeAdapter extends BaseAdapter {
	private Context mContext;
	private List<NoiceListParser> list;

	public NoticeAdapter(Context mContext, List<NoiceListParser> list) {
		super();
		this.mContext = mContext;
		this.list = list;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	
	public void notifyData(List<NoiceListParser> list){
		this.list = list;
		notifyDataSetChanged();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		View v = convertView;
		if (v == null) {
			holder = new ViewHolder();
			v = LayoutInflater.from(mContext).inflate(R.layout.item_notice, null);
			holder.isRead=(TextView) v.findViewById(R.id.item_notice_read);
			holder.content=(TextView) v.findViewById(R.id.item_noticeContent);
			holder.time=(TextView) v.findViewById(R.id.item_noticeTiem);
			v.setTag(holder);
		} else {
			holder = (ViewHolder) v.getTag();
		}
		holder.content.setText(list.get(position).getTitle());
		if(!StringUtils.isEmpty(list.get(position).getCreattime())){
			holder.time.setText(list.get(position).getCreattime());
		}
		if("0".equals(list.get(position).getRead())){
			//已读
			holder.isRead.setText("已读");
			holder.isRead.setTextColor(Color.parseColor("#d1d1d1"));
		}else if("1".equals(list.get(position).getRead())){
			//未读
			holder.isRead.setText("未读");
			holder.isRead.setTextColor(Color.parseColor("#E81010"));
		}
		return v;
	}
	class ViewHolder {
		TextView isRead,content,time;
	}
}